<% layout('/layouts/default.html', {title: '车辆预结算单查询', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('车辆预结算单详情')}
				<% if(hasPermi('settlement:carpresettlement:carPreSettlement:submit') && (tcarPresettlement.approveStatus=='1' || tcarPresettlement.approveStatus=='4')){ %>
					<button type="button" class="btn btn-primary" id="submit"> ${text('提交')}</button>
				<% } %>
				<% if(hasPermi('settlement:carpresettlement:carPreSettlement:approve') && tcarPresettlement.approveStatus=='2'){ %>
					<button type="button" class="btn btn-primary" id="ok"> ${text('通过')}</button>
					<button type="button" class="btn btn-primary" id="reject"> ${text('拒绝')}</button>
				<% } %>
				<% if(hasPermi('settlement:carpresettlement:carPreSettlement:cancel')){ %>
					<button type="button" class="btn btn-primary" id="cancel"> ${text('作废')}</button>
				<% } %>
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${tcarPresettlement}" action="#" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="carPresettlementId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="customerId" items="${customerList}" itemLabel="customerName"
								itemValue="customerId" blankOption="true" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="serviceOrderId" items="${serviceOrderList}" itemLabel="serviceOrderCode"
								itemValue="serviceOrderId" blankOption="true" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('车架号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="frameNumber" items="${frameNumberList}"
								itemLabel="frameNumber" itemValue="frameNumber" blankOption="true" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('预结算汇率')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="presttlementRate" maxlength="10" class="form-control required" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('车辆名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="carName" maxlength="100" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status" dictType="order_status" blankOption="true" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('审批状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select  path="approveStatus" dictType="finance_bill_status" blankOption="true"  class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('客户合计信息')}</h4>
				<div class="ml10 mr10">
					<table id="tcarPresettlementDetailDataGrid1"></table>
				</div>
				<h4 class="form-unit">${text('资方合计信息')}</h4>
				<div class="ml10 mr10">
					<table id="tcarPresettlementDetailDataGrid2"></table>
				</div>
				<div class="form-unit">${text('相关记录')}</div>
				<div class="ml10 mr10">
					<table id="tcarPresettlementDetailDataGrid3"></table>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>

	$("#tcarPresettlementDetailDataGrid3").dataGrid({

		data: ${toJson(tcarPresettlement.relatedRecordList)},
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'${text("单据编号")}', name:'billCode', width:300 },
			{header:'${text("日期")}', name:'date', width:150, },
			{header:'${text("费用项目")}', name:'expenseItem', width:150, editable:true, edittype:'text'},
			{header:'${text("应收金额")}', name:'yingshouAmount', width:150, editable:true, edittype:'text'},
			{header:'${text("应付金额")}', name:'yingfuAmount', width:150, editable:true, edittype:'text'},
			{header:'${text("实收金额")}', name:'shishouAmount', width:150, editable:true, edittype:'text'},
			{header:'${text("实付金额")}', name:'shifuAmount', width:150, editable:true, edittype:'text'},
			{header:'${text("预收金额")}', name:'yushouAmount', width:150, editable:true, edittype:'text'},
			{header:'${text("预付金额")}', name:'yufuAmount', width:150, editable:true, edittype:'text'},
		],

		// 编辑表格参数
		editGrid: false,				// 是否是编辑表格

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});
	function getObjects(obj, key, val) {
		var objects = [];
		for (var i in obj) {
			if (!obj.hasOwnProperty(i)) continue;
			if (typeof obj[i] == 'object') {
				objects = objects.concat(getObjects(obj[i], key, val));
			} else if (i == key && obj[key] == val) {
				objects.push(obj);
			}
		}
		return objects;
	}
</script>

<script>
	let cusList=getObjects(${toJson(tcarPresettlement.tcarPresettlementDetailList)},'type','1');
//初始化车辆预结算详情DataGrid对象
$("#tcarPresettlementDetailDataGrid1").dataGrid({

	data: cusList,
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'carPresettlementDetailId', editable:true, hidden:true},
		{header:'${text("车辆预结算编号")}', name:'carPresettlementId.carPresettlementId', editable:true, hidden:true},
		{header:'${text("车价")}', name:'carPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("币种")}', name:'currency', width:100,
			editable:true, edittype:'select', editoptions:{'class':'form-control'},formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('sys_bizhong')}, val, '${text("未知")}', true);
				}},
		{header:'${text("类型")}', name:'fixedExpense.fixedExpenseName', width:100,editable:true, edittype:'select', editoptions:{'class':'form-control'}},
		{header:'${text("预结算金额")}', name:'presettlementAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("预结算预收余额")}', name:'presettlementAdvancesReceivedAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("差额")}', name:'balance', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],

	// 编辑表格参数
	editGrid: false,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tcarPresettlementDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {carPresettlementDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tcarPresettlementDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,carPresettlementDetailId,carPresettlementId.carPresettlementId,frameNumber,carName,carPrice,currency,chargeType,presettlementAmount,presettlementAdvancesReceivedAmount,balance,type,', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
</script>
<script>
	let invList=getObjects(${toJson(tcarPresettlement.tcarPresettlementDetailList)},'type','2');
	//初始化车辆预结算详情DataGrid对象
	$("#tcarPresettlementDetailDataGrid2").dataGrid({

		data: invList,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度

		// 设置数据表格列
		columnModel: [
			{header:'状态', name:'status', editable:true, hidden:true},
			{header:'主键', name:'carPresettlementDetailId', editable:true, hidden:true},
			{header:'${text("车辆预结算编号")}', name:'carPresettlementId.carPresettlementId', editable:true, hidden:true},
			{header:'${text("车价")}', name:'carPrice', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("币种")}', name:'currency', width:100,
				editable:true, edittype:'select', editoptions:{'class':'form-control'},formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('sys_bizhong')}, val, '${text("未知")}', true);
				}},
			{header:'${text("类型")}', name:'fixedExpense.fixedExpenseName', width:100,editable:true, edittype:'select', editoptions:{'class':'form-control'}},
			{header:'${text("预结算金额")}', name:'presettlementAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("预结算预收余额")}', name:'presettlementAdvancesReceivedAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("差额")}', name:'balance', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
			{header:'${text("操作")}', name:'actions', hidden: true}
		],

		// 编辑表格参数
		editGrid: false,				// 是否是编辑表格
		editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
		editGridAddRowBtn: $('#tcarPresettlementDetailDataGridAddRowBtn'),	// 子表增行按钮
		editGridAddRowInitData: {carPresettlementDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'tcarPresettlementDetailList', // 提交的数据列表名
		editGridInputFormListAttrs: 'status,carPresettlementDetailId,carPresettlementId.carPresettlementId,frameNumber,carName,carPrice,currency,chargeType,presettlementAmount,presettlementAdvancesReceivedAmount,balance,type,', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});
</script>
<script>
// 流程按钮操作事件
$("#ok").click(function(){
	js.confirm('确认通过吗？', function(data){
		$.ajax({
			type: "POST",
			async : false,
			url: "${ctx}/settlement/carpresettlement/carPreSettlement/ok",
			data: {"carPresettlementId": $("#carPresettlementId").val()},
			success: function (data) {
				js.showMessage(data.message);
				location.reload();
			}
		});
	});
});

$("#reject").click(function(){
	js.confirm('确认拒绝吗？', function(data){
		$.ajax({
			type: "POST",
			async : false,
			url: "${ctx}/settlement/carpresettlement/carPreSettlement/reject",
			data: {"carPresettlementId": $("#carPresettlementId").val()},
			success: function (data) {
				js.showMessage(data.message);
				location.reload();
			}
		});
	});
});
//作废
$("#cancel").click(function(){
	js.confirm('确认通过吗？', function(data){
		$.ajax({
			type: "POST",
			async : false,
			url: "${ctx}/settlement/carpresettlement/carPreSettlement/cancel",
			data: {"carPresettlementId": $("#carPresettlementId").val()},
			success: function (data) {
				js.showMessage(data.message);
				location.reload();
			}
		});
	});
});

</script>
